package org.nfyszny.zzzs.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.nfyszny.zzzs.modules.entity.ZzzsPestAndDiseaseControl;
import org.nfyszny.zzzs.modules.mapper.ZzzsPestAndDiseaseControlMapper;
import org.nfyszny.zzzs.modules.service.IZzzsPestAndDiseaseControlService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 病虫害防治
 * @Author: jeecg-boot
 * @Date: 2022-11-10
 * @Version: V1.0
 */
@Service
public class ZzzsPestAndDiseaseControlServiceImpl extends ServiceImpl<ZzzsPestAndDiseaseControlMapper, ZzzsPestAndDiseaseControl> implements IZzzsPestAndDiseaseControlService {

    @Override
    public IPage<ZzzsPestAndDiseaseControl> pageList(Page<ZzzsPestAndDiseaseControl> page, QueryWrapper<ZzzsPestAndDiseaseControl> queryWrapper) {
        Page<ZzzsPestAndDiseaseControl> pageList = this.page(page, queryWrapper);

        List<ZzzsPestAndDiseaseControl> records = pageList.getRecords();
        //根据state变成boolean类型值方便页面渲染
        pageList.setRecords(records.stream().map(item -> {
            item.setStatusBoolean(item.getStatus() == 1);
            return item;
        }).collect(Collectors.toList()));
        return pageList;
    }

    @Override
    public void switchStatus(String id, Integer status) {
        ZzzsPestAndDiseaseControl diseaseControl = new ZzzsPestAndDiseaseControl();
        diseaseControl.setId(id);
        diseaseControl.setStatus(status);
        baseMapper.updateById(diseaseControl);
        System.out.println("diseaseControl = " + diseaseControl);
    }
}
